<template>
  <div>
    <input type="text" v-model="username" />
    <input type="password" v-model="password" />
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: "",
      password: "",
    };
  },
  watch: {
    //当侦听的变量发生了变化,会触发对应函数的执行(拿到最新值,和上一课刻的旧值)
    username(newVal, oldVal) {
      console.log(newVal, oldVal);
    },
    password(newVal, oldVal) {
      console.log(newVal, oldVal);
    },
  },
};
</script>

<style>
</style>